//index.js
//获取应用实例
const app = getApp()
var util = require("../../utils/libs.js")
var api = require("../../utils/api.js")
var date = require("../../utils/date.js")
Page({
  data: {
    publishS:[]
  },
  pub() {
    wx.navigateTo({
      url: '../dragonstory/dragonstory',
    })
  },
  search(keyword){
    let uid = wx.getStorageSync("uid");
    let that = this;
    util.request(api.nextS, { page: '1', key: keyword, limit: '10', uid: uid }, "POST").then(function (res) {
      if (res.error_code === 0) {
        console.log(res);
        let arr = res.data.list
        arr.forEach(e => {
          e.create_time = date.data(e.create_time)
        });
        that.setData({
          publishS: arr
        })
      }
    })
  },
  goSearch (event) {
    let keyword = event.detail.value;
    let uid = wx.getStorageSync("uid");
    let that = this;
    util.request(api.nextS, { page: '1', key:keyword, limit: '10', uid: uid }, "POST").then(function (res) {
      if (res.error_code === 0) {
        console.log(res);
        let arr = res.data.list
        arr.forEach(e => {
          e.create_time = date.data(e.create_time)
        });
        that.setData({
          publishS: arr
        })
      }
    })
  },
  onLoad(options){
    console.log(options)
    this.setData({
      search: options.key
    })
    this.search(options.key)
  }
})
